using BuildingBlocks.Application;
using BuildingBlocks.Application.Behaviors;
using Microsoft.Extensions.DependencyInjection;

namespace Ordering.Application;

public static class DependencyInjection
{
    public static IServiceCollection AddOrderingApplication(this IServiceCollection services)
    {
        services.AddApplication(typeof(DependencyInjection).Assembly);
        services.AddMediator(config =>
        {
            config.GenerateTypesAsInternal = true;
            config.Assemblies = [typeof(DependencyInjection).Assembly];
            config.Namespace = "Ordering.Application";
            config.PipelineBehaviors =
            [
                typeof(LoggingPipelineBehavior<,>),
                typeof(ValidationPipelineBehavior<,>)
            ];
            config.ServiceLifetime = ServiceLifetime.Scoped;
        });

        return services;
    }
}
